<?php
function _get_xml($xmlElements) {
  $xml = "<?xml version=\"1.0\"?><root>";
  foreach ($xmlElements as $xmlElement) {
    $sub = $xmlElement->asXML();
    $xml .= _remove_xml_declaration($sub);
  }
  $xml .= "</root>"; 
  return $xml;
}

function _remove_xml_declaration($xml) {
  $groups = array();
  $regex = "/(\<\?.*\?\>)+/";
  preg_match($regex, $xml, $groups);
  if (sizeof($groups) > 0) {
    $declaration = $groups[0];
    return str_replace($declaration, "", $xml);
  } else {
    return $xml;
  }
}

